Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Use same Task for Task.CompletedTask and ATMB.Completed #24404

Closed
wants to merge 3 commits into from

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented May 5, 2019

Keep it hotter in cache rather than alternating between the two for manually and compiler generated async methods

/cc @stephentoub

@@ -270,7 +263,7 @@ public Task Task
/// </summary>
/// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception>
/// <exception cref="System.InvalidOperationException">The task has already completed.</exception>
public void SetResult() => m_builder.SetResult(s_cachedCompleted); // Using s_cachedCompleted is faster than using s_defaultResultTask.
public void SetResult() => m_builder.SetResult(Task.s_cachedCompleted); // Using s_cachedCompleted is faster than using s_defaultResultTask via generic.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you confirmed the asm for this is just as good?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, ends up identical

  [12 IL=0141 TR=000050 060036BE] [profitable inline] AsyncTaskMethodBuilder:SetResult():this
    [13 IL=0011 TR=000240 060036D0] [profitable inline] AsyncTaskMethodBuilder`1:SetResult(ref):this
      [0 IL=0026 TR=000260 060036CE] [FAILED: too many basic blocks] AsyncTaskMethodBuilder`1:SetExistingTaskResult(struct):this
      ...
; Total bytes of code 339, prolog size 29 for method <Main>d__0:MoveNext():this

Its going via a generic rather than non-generic that causes the speed bump

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, ends up identical

More or less

-      BAA4040000           mov      edx, 0x4A4
+      BA84020000           mov      edx, 644
       E89B83B25F           call     CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE
-      48BA80190AD3E5010000 mov      rdx, 0x1E5D30A1980
+      48BA381647D6FC010000 mov      rdx, 0x1FCD6471638
       488B12               mov      rdx, gword ptr [rdx]

@benaadams
Copy link
Member Author

CI looks quite broken

coreclr-ci
 Failure
 ran 20 seconds ago in less than 5 seconds

Pipeline configuration error:
/azure-pipelines.yml: Could not find /eng/platform-matrix.yml in repository self hosted on 
https://api.github.com using commit 16a840c2fb45164924979bace155dc2ca5522bd9. 
GitHub reported the error, "Not Found"

@benaadams
Copy link
Member Author

Code gen ends up identical in usage (other than referring to same object) and a change in .cctors

Total bytes of diff: -31 (-0.00% of base)
    diff is an improvement.

Total byte diff includes -55 bytes from reconciling methods
        Base had    1 unique methods,       55 unique bytes
        Diff had    0 unique methods,        0 unique bytes

Top file improvements by size (bytes):
         -31 : System.Private.CoreLib.dasm (-0.00% of base)

1 total files with size differences (1 improved, 0 regressed), 0 unchanged.

Top method regressions by size (bytes):
          24 (13.87% of base) : System.Private.CoreLib.dasm - Task:.cctor()

Top method improvements by size (bytes):
         -55 (-100.00% of base) : System.Private.CoreLib.dasm - AsyncTaskMethodBuilder:.cctor() (1 base, 0 diff methods)

2 total methods with size differences (1 improved, 1 regressed), 18365 unchanged.

@benaadams
Copy link
Member Author

Follow up that takes this a bit further #24431

@benaadams
Copy link
Member Author

benaadams commented May 12, 2019

Closing in preference of #24431

@benaadams benaadams closed this May 12, 2019
@benaadams benaadams deleted the CompletedTask branch May 30, 2019 16:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants